/*
 *  Population.h
 *  Genetski
 *
 *  Created by Srđan Rašić on 11/19/11.
 *
 */

#pragma once
#include <vector>
#include "Chromosome.h"
#include "Function.h"

/**
 * Represents population of chromosomes - candidate solutions.
 */
class Population : public std::vector<Chromosome> {
private:
	double _maxFuncValue;
	double _minFuncValue;
	bool _minimization;
	Function& _function;
	int _chromosomeSize;
	
	int _bestChromosomeIndex;
	
	bool exists(Chromosome& ch);
public:
	/**
	 * Generates initial population defined by parameters.
	 * @param f Function to optimize
	 * @param numberOfIndividuals Number of chromosomes in population
	 * @param minimization True if should minimize, otherwise False
	 * @param precision To which decimal precision should search for solution
	 */
	Population(Function& f, unsigned int numberOfIndividuals, bool minimization, int precision);
	
	int& BestIndividualIndex();
	
	std::vector<double> ChromosomeValue(unsigned int index);
	
	/**
	 * Returns fitness value of chromosome.
	 * @param index Index of chromosome in population
	 */
	double Fitness(unsigned int index);
};